<template>
  <a-table
    rowKey="id"
    :columns="columns"
    :data-source="dataSource"
  >
    <template slot="status" slot-scope="record">
      <span v-if="record.state === 'NEW'"><a-badge status="processing" /> {{ record.stateDesc }}</span>
      <span v-if="record.state === 'DONE'"><a-badge status="success" /> {{ record.stateDesc }}</span>
    </template>
    <template slot="operation" slot-scope="record">
      <a-button type="link" @click="handleGrade(record)">打分</a-button>
    </template>
  </a-table>
</template>

<script>
// tools
import { convertNumberToTime } from '@/utils/handleTime'

// 常量
const missionColumns = [
  { title: '目标内容', dataIndex: 'content', key: 'content' },
  { title: '状态', key: 'status', scopedSlots: { customRender: 'status' } },
  { title: '到期日', dataIndex: 'dueDate', key: 'dueDate', customRender: convertNumberToTime },
  { title: '操作', key: 'operation', scopedSlots: { customRender: 'operation' } }
]
export default {
  props: {
    dataSource: {
      type: Array,
      required: true
    },
    isInTeam: {
      type: Boolean,
      required: true
    }
  },
  data () {
    return {
      missionColumns
    }
  },
  computed: {
    columns () {
      if (this.isInTeam) {
        return missionColumns
      } else {
        const newColumns = missionColumns.slice(0, -1)
        return newColumns
      }
    }
  },
  methods: {
    handleGrade (mission) {
      this.$emit('grade', mission)
    }
  }
}
</script>
